package com.tanhua.server.controller;

import com.tanhua.domain.vo.CommentVo;
import com.tanhua.domain.vo.PageResult;
import com.tanhua.server.service.CommentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.Map;

@RestController
@RequestMapping("/comments")
public class CommentController {

    @Autowired
    private CommentService commentService;

    /**
     * 某个动态的评论列表
     * @param page
     * @param pageSize
     * @param publishId
     * @return
     */
    @GetMapping
    public ResponseEntity commentList(@RequestParam(value = "page",defaultValue="1") Long page,
                                      @RequestParam(value = "pagesize",defaultValue="10")Long pageSize,
                                      @RequestParam(value = "movementId") String publishId){
        PageResult pageResult = commentService.findPage(publishId, page, pageSize);
        return ResponseEntity.ok(pageResult);
    }

    /**
     * 对动态发表评论
     * @param paramMap
     * @return
     */
    @PostMapping
    public ResponseEntity add(@RequestBody Map<String,String> paramMap){
        commentService.add(paramMap);
        return ResponseEntity.ok(null);
    }

    /**
     * 对评论的点赞
     * @param commentId
     * @return
     */
    @GetMapping("/{commentId}/like")
    public ResponseEntity like(@PathVariable String commentId){
        int likeCount = commentService.likeComment(commentId);
        return ResponseEntity.ok(likeCount);
    }

    /**
     * 对评论的取消点赞
     * @param commentId
     * @return
     */
    @GetMapping("/{commentId}/dislike")
    public ResponseEntity dislike(@PathVariable String commentId){
        int likeCount = commentService.dislikeComment(commentId);
        return ResponseEntity.ok(likeCount);
    }
}
